home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / BASIC / LIB / EVENTSHELL / EXTENSION / DatePick (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1996-02-13  |  10KB  |  241 lines

  1.  Module DatePick
  2.  -----------------------------------------------------------------------
  3.  DatePick Handling Routines (version 1.03 13-Feb-96)
  4.  This library contains the 'DatePick' support routines. 'DatePick' is a
  5.  popup dialogue box which allows the choice of a date from a calendar
  6.  type display. Normally the calendar which shows the current date is
  7.  opened, but any other calendar can be displayed,
  8.  -----------------------------------------------------------------------
  9.  Public Methods Supported:
  10.    FN_shell_DatePick_Init          Initialises module
  11.    PROCshell_AttachPopupDatePicker Attaches the DatePicker to a window/icon
  12.  Responses to events raised by other modules
  13.    PROCshell_DatePickerOpen        Opens the DatePick DBox
  14.  Private Methods Supported:
  15.    PROCDatePicker_PreOpen
  16.    PROCDatePicker_Selection
  17.    FN_DatePicker_BumpHandler
  18.    FN_DatePicker_BumpHandler2
  19.    FN_DatePicker_DecodeDate
  20.    FN_DatePicker_Click
  21.  Message Strings required by module
  22.    monthstr
  23.    daystr
  24.    today
  25. ""*|Start FN_shell_DatePick_Init
  26. _shell_DatePick_Init
  27.  Define Constants
  28. '@_c_DatePick_TodayIcon%        = 0    : 
  29.  Default action icon
  30. (O_c_DatePick_FirstIcon%        = 11   : 
  31.  First icon that holds a day number
  32. )O_c_DatePick_LastIcon%         = 53   : 
  33.  Last  icon that holds a day number
  34. *N_c_DatePick_MonthIcon%        = 1    : 
  35.  Icon handle of month display icon
  36. +M_c_DatePick_MonthIncIcon%     = 3    : 
  37.  Icon handle month increment icon
  38. ,M_c_DatePick_MonthDecIcon%     = 4    : 
  39.  Icon handle month decrement icon
  40. -K_c_DatePick_YearIcon%         = 2    : 
  41.  Icon handle year  display icon
  42. .L_c_DatePick_YearIncIcon%      = 55   : 
  43.  Icon handle year increment icon
  44. /L_c_DatePick_YearDecIcon%      = 54   : 
  45.  Icon handle year decrement icon
  46. 0K_c_DatePick_FirstWeekDayIcon% = 5    : 
  47.  Icon handle first weekday icon
  48. 2H_c_DatePick_ESG%              = 1            : 
  49.  ESG of day nr icons
  50. 3J_c_DatePick_Sep$              = "."          : 
  51.  Date seperater string
  52. 4H_c_DatePick_TemplateName$     = "datepicker" : 
  53.  Template identifier
  54.  Define variables
  55. 7>_m_DatePick_DBoxHandle%     = -1    : 
  56.  DBox window handle
  57. 8`_m_DatePick_NotifyFN$       = ""    : 
  58.  FN to call when selection is made in datepicker dbox
  59. 9T_m_DatePick_WindowHandle%   = -1    : 
  60.  Handle of window containing display icon
  61. :Y_m_DatePick_DisplayIcon%    = -1    : 
  62.  Handle of icon to display resulting selection
  63. ;$_m_DatePick_CurrDay%        = -1
  64. <$_m_DatePick_CurrMonth%      = -1
  65. =$_m_DatePick_CurrYear%       = -1
  66. A#*|extract FN_DatePicker_PreOpen
  67. B'*|extract FN_DatePicker_BumpHandler
  68. C(*|extract FN_DatePicker_BumpHandler2
  69. D&*|extract FN_DatePicker_DecodeDate
  70. E!*|extract FN_DatePicker_Click
  71. F-*|extract PROCshell_AttachPopupDatePicker
  72. H!*|Stop FN_shell_DatePick_Init
  73. L$*|Start PROCshell_DatePickerOpen
  74. *|!PROCshell_DatePickerOpen
  75. O8*|!Opens the datepicker dbox and calls the specified
  76. P(*|!routine when a selection is made.
  77. shell_DatePickerOpen( window_handle%, display_icon%, menu_icon%, notify_FN$ )
  78. S._m_DatePick_WindowHandle% = window_handle%
  79. T-_m_DatePick_DisplayIcon%  = display_icon%
  80. U*_m_DatePick_NotifyFN$     = notify_FN$
  81. shell_OpenWindowDynamic( _c_DatePick_TemplateName$, "_DatePicker_PreOpen", "" )
  82. shell_WindowMoveToPopUpPos( window_handle%, menu_icon%, 
  83. shell_GetDynamicWindowHandle )
  84. Z#*|Stop PROCshell_DatePickerOpen
  85. ^!*|Start FN_DatePicker_PreOpen
  86. _DatePicker_PreOpen( window_handle% )
  87.  loop%,monthstr$, daystr$
  88. c,_m_DatePick_DBoxHandle% = window_handle%
  89.  "XHourglass_On"
  90.  Fill in weekday names..
  91.  loop% = 0 
  92. shell_IconPutData( _m_DatePick_DBoxHandle%, _c_DatePick_FirstWeekDayIcon% + loop%, 
  93. shell_CalendarWeekDayString( loop% + 1 ), 
  94.  loop%
  95.  And 'Today' button..
  96. shell_IconPutData( _m_DatePick_DBoxHandle%, _c_DatePick_TodayIcon%, 
  97. shell_MessageNoArgs( "today" ), 
  98. shell_AttachClickSelect( _m_DatePick_DBoxHandle%, -1, "_DatePicker_Click" )
  99. shell_AttachHelpTag( _m_DatePick_DBoxHandle%, -1, "dpwin" )
  100. shell_CalendarGetTodaysDate( _m_DatePick_CurrDay% , _m_DatePick_CurrMonth% , _m_DatePick_CurrYear% )
  101. shell_DatePickerCreateCalendar( _m_DatePick_CurrDay%, _m_DatePick_CurrMonth% , _m_DatePick_CurrYear% )
  102. shell_AttachBumpHandler( _m_DatePick_DBoxHandle%, _c_DatePick_MonthIcon%, _c_DatePick_MonthIncIcon%, _c_DatePick_MonthDecIcon%, -9999, 9999, 1, 
  103. , "_DatePicker_BumpHandler" , "_DatePicker_DecodeDate" )
  104. shell_AttachBumpHandler( _m_DatePick_DBoxHandle%, _c_DatePick_YearIcon%, _c_DatePick_YearIncIcon%, _c_DatePick_YearDecIcon%, -9999, 9999, 1, 
  105. , "_DatePicker_BumpHandler2" , "" )
  106.  "Hourglass_Off"
  107. | *|Stop FN_DatePicker_PreOpen
  108. .*|Start PROCshell_DatePickerCreateCalendar
  109. shell_DatePickerCreateCalendar( day%, month%, year% )
  110.  day_of_week%, month_str$, day_nr%, start_icon%, days_in_month%
  111.  selected%
  112.  "Hourglass_On"
  113. B  days_in_month% = 
  114. shell_CalendarDaysInMonth( month%, year% )
  115. A  day_of_week% = 
  116. shell_CalendarDayOfWeek( 1, month%, year% )
  117. 7  month_str$ = 
  118. shell_CalendarMonthString( month% )
  119. shell_CloseWindow( _m_DatePick_DBoxHandle% )
  120. shell_IconPutData( _m_DatePick_DBoxHandle%, _c_DatePick_YearIcon%,  
  121. ( year% ), 
  122. shell_IconPutData( _m_DatePick_DBoxHandle%, _c_DatePick_MonthIcon%, month_str$, 
  123. :  start_icon%  = _c_DatePick_FirstIcon% + day_of_week%
  124.  Make first and last rows non-responsive to mouse clicks..
  125.  icon% = 1 
  126. ^    
  127. shell_IconSetButtonType( _m_DatePick_DBoxHandle%, icon% + _c_DatePick_FirstIcon%, 0 )
  128. \    
  129. shell_IconPutData( _m_DatePick_DBoxHandle%, icon% + _c_DatePick_FirstIcon%, "", 
  130. H    
  131. shell_IconPutData( _m_DatePick_DBoxHandle%, icon% + 39, "", 
  132. J    
  133. shell_IconSetButtonType( _m_DatePick_DBoxHandle%, icon% + 39, 0 )
  134. J    
  135. shell_IconSetButtonType( _m_DatePick_DBoxHandle%, icon% + 46, 0 )
  136. H    
  137. shell_IconPutData( _m_DatePick_DBoxHandle%, icon% + 46, "", 
  138.  icon%
  139.  Deselect any selected icons in the ESG
  140. X  selected% = 
  141. shell_IconRadioSelection( _m_DatePick_DBoxHandle%, _c_DatePick_ESG% )
  142.  selected% >= 0 
  143. shell_IconSet( _m_DatePick_DBoxHandle%, selected%, 0 )
  144.  day_nr% = 1 
  145.  days_in_month%
  146. a    
  147. shell_IconPutData( _m_DatePick_DBoxHandle%, start_icon% + day_nr% - 1, 
  148. ( day_nr% ), 
  149. Y    
  150. shell_IconSetButtonType( _m_DatePick_DBoxHandle%, start_icon% + day_nr% - 1, 3 )
  151. l    
  152.  day_nr% = _m_DatePick_CurrDay% 
  153.  month% = _m_DatePick_CurrMonth% 
  154.  year% = _m_DatePick_CurrYear% 
  155. Q      
  156. shell_IconSet( _m_DatePick_DBoxHandle%, start_icon% + day_nr% - 1, 1 )
  157.         
  158.  day_nr%
  159. shell_OpenWindow( _m_DatePick_DBoxHandle%, 
  160.  "Hourglass_Off"
  161. -*|Stop PROCshell_DatePickerCreateCalendar
  162. %*|Start FN_DatePicker_BumpHandler
  163. _DatePicker_BumpHandler( month%, button% )
  164.  year%
  165. Uyear% = 
  166. shell_IconGetData( _m_DatePick_DBoxHandle%, _c_DatePick_YearIcon% ) )
  167.  month% < 1 
  168.   year% -= 1
  169.   month% = 12
  170.  month% > 12 
  171.   year% += 1
  172.   month% = 1
  173. shell_DatePickerCreateCalendar( 1, month%, year% )
  174. shell_CalendarMonthString( month% )
  175. $*|Stop FN_DatePicker_BumpHandler
  176. &*|Start FN_DatePicker_BumpHandler2
  177. _DatePicker_BumpHandler2( year%, button% )
  178.  month%
  179. pmonth% = 
  180. shell_CalendarMonthNumber( 
  181. shell_IconGetData( _m_DatePick_DBoxHandle%, _c_DatePick_MonthIcon% ) )
  182. shell_DatePickerCreateCalendar( 1, month%, year% )
  183. ( year% )
  184. %*|Stop FN_DatePicker_BumpHandler2
  185. $*|Start FN_DatePicker_DecodeDate
  186. _DatePicker_DecodeDate( month$ )
  187. shell_CalendarMonthNumber( month$ )
  188. #*|Stop FN_DatePicker_DecodeDate
  189. *|Start FN_DatePicker_Click
  190. _DatePicker_Click( window_handle%, icon_handle% )
  191.  _date$, day%, month%, year%, offset%
  192.  icon_handle% > _c_DatePick_FirstIcon% 
  193.  icon_handle% < _c_DatePick_LastIcon% 
  194. i  month% = 
  195. shell_CalendarMonthNumber( 
  196. shell_IconGetData( window_handle%, _c_DatePick_MonthIcon% ) )
  197. c  _date$  = 
  198.  "0" + 
  199. shell_IconGetData( window_handle%, icon_handle% ), _c_DatePick_YearIcon% )
  200. N  _date$ += _c_DatePick_Sep$ + 
  201.  "0" + 
  202. ( month% ), 2 ) + _c_DatePick_Sep$
  203. R  _date$ += 
  204. shell_IconGetData( window_handle%, _c_DatePick_YearIcon% ), 2 )
  205. shell_CloseWindow( window_handle% )
  206. DatePicker_Selection( _date$ )
  207.  icon_handle% = 0 
  208. shell_CalendarGetTodaysDate( day% , month% , year% )
  209. ;  _date$  = 
  210.  "0" + 
  211. ( day%   ), 2 ) + _c_DatePick_Sep$
  212. ;  _date$ += 
  213.  "0" + 
  214. ( month% ), 2 ) + _c_DatePick_Sep$
  215. !  _date$ += 
  216. ( year% ), 2 )
  217. shell_CloseWindow( window_handle% )
  218. DatePicker_Selection( _date$ )
  219. *|Stop FN_DatePicker_Click
  220. $*|Start PROCDatePicker_Selection
  221. DatePicker_Selection( _date$ )
  222.  void%
  223.  _m_DatePick_NotifyFN$ <> "" 
  224. <  void% = 
  225. ( "FN" + _m_DatePick_NotifyFN$ + "(_date$)" )
  226.  _m_DatePick_DisplayIcon% >= 0 
  227. \    
  228. shell_IconPutData( _m_DatePick_WindowHandle%, _m_DatePick_DisplayIcon%, _date$, 
  229. #*|Stop PROCDatePicker_Selection
  230. +*|Start PROCshell_AttachPopupDatePicker
  231. shell_AttachPopupDatePicker( wh%, menuic%, dispic%, notify_fn$, preopen_FN$ )
  232. shell_WindowLoaded( _c_DatePick_TemplateName$ ) 
  233.  wh% > 0 
  234.  menuic% >= 0 
  235. shell_IconSetButtonType( wh%, menuic%, 3 )
  236. shell_EvntAdd_PopUpMenu( 
  237. shell_GetWindowIdentifier( wh% ), menuic%, dispic%, -1, notify_fn$, preopen_FN$, _POPUP_TYPE_DATEPICK )
  238.  99, 
  239. shell_MessageOneArg( "SHELLMSG37", _c_DatePick_TemplateName$ )
  240. **|Stop PROCshell_AttachPopupDatePicker
  241.